#include "stdafx.h"
#include "CRC_Check.h"

#define CRC32_POLYNOMIAL 0xEDB88320L

Uint32 CRC32Value(int i)
{
	int j;
	Uint32 ulCRC;
	ulCRC = i;
	for ( j = 8; j >0; j--)
	{
		if (ulCRC & 0x01)
			ulCRC = (ulCRC>>1)^CRC32_POLYNOMIAL;
		else
			ulCRC>>=1;
	}
	return ulCRC;
}
Uint32 CalculateBlockCRC32(Uint32 ulCount, Uint8 *ucBuffer)
{
	Uint32 ulTemp1;
	Uint32 ulTemp2;
	Uint32 ulCRC = 0;
	while( ulCount--!=0)
	{
		ulTemp1 = (ulCRC >>8) & 0x00FFFFFFL;
		ulTemp2 = CRC32Value(((int) ulCRC ^ *ucBuffer++) & 0xff);
		ulCRC = ulTemp1 ^ ulTemp2;
	}
	return(ulCRC);
}